

import 'dart:convert';

import 'package:excel_utils/pages/week/bean/RincosBean.dart';
import 'package:excel_utils/pages/week/bean/MonthlyPackageTransferBean.dart';
import 'package:excel_utils/pages/week/week_entry/child/dis_customer_record/dis_customer_record_page.dart';
import 'package:excel_utils/repository/constant.dart';
import 'package:excel_utils/service/DioManager.dart';

abstract class IRincosRepository {

  Future<List<RincosBean>> getRincosData({maps});

  Future<List<RincosBean>> saveRincosData({required List<RincosBean> rincosData});

  Future<String> deleteRincosData({required String rincosId});

}


class RincosRepository implements IRincosRepository {

  DioManager dioManager = DioManager();

  @override
  Future<String> deleteRincosData({required String rincosId}) async {
    final response = await dioManager.get(path: "${Constant.RincosDeleteUrl}?rincosId=$rincosId");
    dynamic result = json.decode(response.toString());
    if (result["code"] == 0) {
      return result["data"];
    } else {
      return "-1";
    }
  }

  @override
  Future<List<RincosBean>> getRincosData({maps}) async {
    final response = await dioManager.get(path: "${Constant.RincosDataUrl}", queryParameters: maps);
    List<RincosBean> data = [];
    dynamic result = json.decode(response.toString());
    if (result["code"] == 0) {
      result['data'].forEach((v) {
        data.add(RincosBean.fromJson(v));
      });
      return data;
    } else {
      return [];
    }
  }

  @override
  Future<List<RincosBean>> saveRincosData({required List<RincosBean> rincosData}) async {
    String jsonData = json.encode(rincosData);
    print(jsonData);
    final response = await dioManager.post(path: "${Constant.RincosAddUrl}", data: jsonData);
    List<RincosBean> data = [];
    dynamic result = json.decode(response.toString());
    if (result["code"] == 0) {
      result['data'].forEach((v) {
        data.add(RincosBean.fromJson(v));
      });
      return data;
    } else {
      return [];
    }
  }

}